<template>
  <el-dialog
    v-model="visible"
    :title="$t('shopProcess.changeBusinessInfor')"
    :append-to-body="true"
    :close-on-click-modal="false"
    top="10vh"
    width="70%"
    class="component-audit-business-infor"
  >
    <div class="popup">
      <!-- 修改信息 -->
      <el-form
        ref="modifyInformationRef"
        label-width="140px"
        :class="{'en-form':$t('language')==='English'}"
        :model="modifyInformation"
        @submit.prevent
      >
        <div class="ci-wrapper">
          <div class="left-item-wrap">
            <el-form-item
              :label="$t('shopProcess.creditCode') + '：'"
              required
            >
              {{ modifyInformation.creditCode }}
            </el-form-item>
            <el-form-item
              :label="$t('shopProcess.firmName') + '：'"
              required
            >
              {{ modifyInformation.firmName }}
            </el-form-item>
            <el-form-item
              :label="$t('shopProcess.representative') + '：'"
              required
            >
              {{ modifyInformation.representative }}
            </el-form-item>
            <el-form-item :label="$t('shopProcess.capital') + '：'">
              <span v-if="modifyInformation.capital"> {{ modifyInformation.capital }} {{ $t("shopProcess.tenThousandYuan") }}</span>
              <span
                v-else
                class="noyet-wrap"
              >{{ $t('shopProcess.notYet') }}</span>
            </el-form-item>
            <el-form-item :label="$t('shopProcess.residence') + '：'">
              <span v-if="modifyInformation.residence"> {{ modifyInformation.residence }} </span>
              <span
                v-else
                class="noyet-wrap"
              >{{ $t('shopProcess.notYet') }}</span>
            </el-form-item>
            <el-form-item :label="$t('shopProcess.fountTime') + '：'">
              <span v-if="modifyInformation.foundTime"> {{ modifyInformation.foundTime.split(' ')[0] }} </span>
              <span
                v-else
                class="noyet-wrap"
              >{{ $t('shopProcess.notYet') }}</span>
            </el-form-item>
            <el-form-item
              :label="$t('shopProcess.businessPeriod') + '：'"
            >
              <span v-if="modifyInformation.startTime && modifyInformation.endTime">
                {{ modifyInformation.startTime.slice(0, 10) + ' - ' + modifyInformation.endTime.slice(0, 10) }}
              </span>
              <span v-else-if="modifyInformation.startTime">
                {{ modifyInformation.startTime.slice(0, 10) + ' - ' + $t('shopProcess.noFixedTerm') }}
              </span>
              <span v-else>
                {{ $t('shopProcess.notYet') }}
              </span>
            </el-form-item>
            <el-form-item
              :label="$t('shopProcess.businessScope') + '：'"
              required
            >
              <span class="businessScope">
                {{ modifyInformation.businessScope }}
              </span>
            </el-form-item>
          </div>
          <div class="right-item-wrap">
            <!-- 右侧图片 -->
            <el-form-item
              :label="$t('shopProcess.businessLicense') + '：'"
              required
            >
              <div class="business-license-box">
                <div class="logo-image-box">
                  <el-image
                    v-if="modifyInformation.businessLicense"
                    class="logo-image"
                    :src="checkFileUrl(modifyInformation.businessLicense)"
                    :preview-src-list="[checkFileUrl(modifyInformation.businessLicense)]"
                  />
                </div>
              </div>
            </el-form-item>
            <el-form-item
              :label="$t('shopProcess.corporateIdentityCard') + '：'"
              required
            >
              <div class="business-license-box">
                <div class="logo-image-box">
                  <el-image
                    v-if="modifyInformation.identityCardFront"
                    class="logo-image"
                    :src="checkFileUrl(modifyInformation.identityCardFront)"
                    :preview-src-list="[checkFileUrl(modifyInformation.identityCardFront)]"
                  />
                  <el-image
                    v-if="modifyInformation.identityCardLater"
                    class="logo-image"
                    :src="checkFileUrl(modifyInformation.identityCardLater)"
                    :preview-src-list="[checkFileUrl(modifyInformation.identityCardLater)]"
                  />
                </div>
              </div>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <!-- 审核状态 -->
      <div class="audit-status-wrap">
        <div class="cloumn-item">
          {{ $t('shopProcess.auditStatus') }}：
        </div>
        <el-radio
          v-model="auditRadio"
          disabled
          label="0"
        >
          {{ $t('shopProcess.onlinePendingReview') }}
        </el-radio>
        <el-radio
          v-model="auditRadio"
          label="1"
        >
          {{ $t('shopProcess.passed') }}
        </el-radio>
        <el-radio
          v-model="auditRadio"
          label="-1"
        >
          {{ $t('shopProcess.notThrough') }}
        </el-radio>
      </div>
      <div
        v-show="auditRadio== -1"
        class="reason-wrap"
      >
        <span>{{ $t('shopProcess.rejectReason') + '：' }}</span>
        <el-input
          v-model="remarks"
          type="textarea"
          show-word-limit
          maxlength="50"
          :placeholder="$t('shopProcess.rejectReason')"
        />
      </div>
    </div>
    <template #footer>
      <div
        class="dialog-footer"
      >
        <div
          class="default-btn"
          @click="closePop"
        >
          {{ $t('shopProcess.close') }}
        </div>
        <div
          class="default-btn primary-btn"
          @click="subAuditResult"
        >
          {{ $t('shopProcess.confirm') }}
        </div>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ElMessage } from 'element-plus'

const emit = defineEmits(['closePops'])

const visible = ref(false) // 控制显示
const init = (id) => {
  visible.value = true
  if (id) getmodifyInformation(id)
}

const modifyInformation = ref({
  creditCode: '',
  firmName: '',
  representative: '',
  capital: '',
  residence: '',
  foundTime: '',
  startTime: '',
  endTime: '',
  businessScope: '',
  businessLicense: '',
  identityCardFront: '',
  identityCardLater: ''
})
const auditRadio = ref('0') // 审核状态选择
const remarks = ref('') // 拒绝原因
const getmodifyInformation = (shopId) => {
  http({
    url: http.adornUrl('/platform/companyAuditing/auditInfo'),
    method: 'get',
    params: http.adornParams({
      shopId
    })
  }).then(({ data }) => {
    nextTick(() => {
      modifyInformation.value = { ...data, ...data.shopCompany }
      auditRadio.value = data.status
    })
  })
}
// 确定审核结果
const subAuditResult = () => {
  // 拦截
  if (auditRadio.value == '0') {
    return ElMessage({
      message: $t('shopProcess.auditTip1'),
      type: 'error',
      duration: 1500
    })
  }
  if (auditRadio.value == '-1' && !remarks.value.trim()) {
    return ElMessage({
      message: $t('shopProcess.auditTip3'),
      type: 'error',
      duration: 1500
    })
  }
  const param = {
    companyAuditingId: modifyInformation.value.companyAuditingId,
    shopCompanyId: modifyInformation.value.shopCompanyId,
    shopId: modifyInformation.value.shopId,
    status: auditRadio.value,
    remarks: remarks.value
  }
  http({
    url: http.adornUrl('/platform/companyAuditing/audit'),
    method: 'put',
    data: http.adornData(param)
  }).then(() => {
    ElMessage({
      message: $t('shopProcess.auditTip2'),
      type: 'success',
      duration: 1500,
      onClose: () => {
        closePop()
      }
    })
  }).catch(() => {
    closePop()
  })
}

// 关闭弹窗
const closePop = () => {
  visible.value = false
  emit('closePops')
}

defineExpose({
  init
})

</script>

<style lang="scss" scoped>
@use "index";
</style>
